
<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>pymatgen.analysis.chemenv.utils.chemenv_config &#8212; pymatgen 2020.7.3 documentation</title>
    <link rel="stylesheet" href="../../../../../_static/basic.css" type="text/css" />
    <link rel="stylesheet" href="../../../../../_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="../../../../../" src="../../../../../_static/documentation_options.js"></script>
    <script src="../../../../../_static/jquery.js"></script>
    <script src="../../../../../_static/underscore.js"></script>
    <script src="../../../../../_static/doctools.js"></script>
    <script src="../../../../../_static/language_data.js"></script>
    <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="index" title="Index" href="../../../../../genindex.html" />
    <link rel="search" title="Search" href="../../../../../search.html" />
 
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-33990148-1']);
  _gaq.push(['_trackPageview']);
</script>

  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../../../pymatgen.html" accesskey="U">pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.analysis.chemenv.utils.chemenv_config</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
          <div class="body" role="main">
            
  <h1>Source code for pymatgen.analysis.chemenv.utils.chemenv_config</h1><div class="highlight"><pre>
<span></span><span class="c1"># coding: utf-8</span>
<span class="c1"># Copyright (c) Pymatgen Development Team.</span>
<span class="c1"># Distributed under the terms of the MIT License.</span>

<span class="kn">from</span> <span class="nn">pymatgen.analysis.chemenv.utils.scripts_utils</span> <span class="kn">import</span> <span class="n">strategies_class_lookup</span>
<span class="kn">from</span> <span class="nn">os.path</span> <span class="kn">import</span> <span class="n">expanduser</span><span class="p">,</span> <span class="n">exists</span>
<span class="kn">from</span> <span class="nn">os</span> <span class="kn">import</span> <span class="n">makedirs</span>
<span class="kn">import</span> <span class="nn">json</span>

<span class="kn">from</span> <span class="nn">pymatgen</span> <span class="kn">import</span> <span class="n">SETTINGS</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">This module contains the classes for configuration of the chemenv package.</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="n">__author__</span> <span class="o">=</span> <span class="s2">&quot;David Waroquiers&quot;</span>
<span class="n">__copyright__</span> <span class="o">=</span> <span class="s2">&quot;Copyright 2012, The Materials Project&quot;</span>
<span class="n">__credits__</span> <span class="o">=</span> <span class="s2">&quot;Geoffroy Hautier&quot;</span>
<span class="n">__version__</span> <span class="o">=</span> <span class="s2">&quot;2.0&quot;</span>
<span class="n">__maintainer__</span> <span class="o">=</span> <span class="s2">&quot;David Waroquiers&quot;</span>
<span class="n">__email__</span> <span class="o">=</span> <span class="s2">&quot;david.waroquiers@gmail.com&quot;</span>
<span class="n">__date__</span> <span class="o">=</span> <span class="s2">&quot;Feb 20, 2016&quot;</span>


<div class="viewcode-block" id="ChemEnvConfig"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.utils.chemenv_config.html#pymatgen.analysis.chemenv.utils.chemenv_config.ChemEnvConfig">[docs]</a><span class="k">class</span> <span class="nc">ChemEnvConfig</span><span class="p">():</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Class used to store the configuration of the chemenv package :</span>
<span class="sd">     - Materials project access</span>
<span class="sd">     - ICSD database access</span>
<span class="sd">     - Default options (strategies, ...)</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">DEFAULT_PACKAGE_OPTIONS</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s1">&#39;default_strategy&#39;</span><span class="p">:</span> <span class="p">{</span>
            <span class="s1">&#39;strategy&#39;</span><span class="p">:</span> <span class="s1">&#39;SimplestChemenvStrategy&#39;</span><span class="p">,</span>
            <span class="s1">&#39;strategy_options&#39;</span><span class="p">:</span> <span class="p">{</span>
                <span class="s1">&#39;distance_cutoff&#39;</span><span class="p">:</span> <span class="n">strategies_class_lookup</span><span class="p">[</span><span class="s1">&#39;SimplestChemenvStrategy&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">DEFAULT_DISTANCE_CUTOFF</span><span class="p">,</span>
                <span class="s1">&#39;angle_cutoff&#39;</span><span class="p">:</span> <span class="n">strategies_class_lookup</span><span class="p">[</span><span class="s1">&#39;SimplestChemenvStrategy&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">DEFAULT_ANGLE_CUTOFF</span><span class="p">,</span>
                <span class="s1">&#39;additional_condition&#39;</span><span class="p">:</span> <span class="n">strategies_class_lookup</span><span class="p">[</span><span class="s1">&#39;SimplestChemenvStrategy&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">DEFAULT_ADDITIONAL_CONDITION</span><span class="p">,</span>
                <span class="s1">&#39;continuous_symmetry_measure_cutoff&#39;</span><span class="p">:</span>
                    <span class="n">strategies_class_lookup</span><span class="p">[</span><span class="s1">&#39;SimplestChemenvStrategy&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">DEFAULT_CONTINUOUS_SYMMETRY_MEASURE_CUTOFF</span><span class="p">}},</span>
        <span class="s1">&#39;default_max_distance_factor&#39;</span><span class="p">:</span> <span class="mf">1.5</span>
    <span class="p">}</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">package_options</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">SETTINGS</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;PMG_MAPI_KEY&quot;</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">)</span> <span class="o">!=</span> <span class="s2">&quot;&quot;</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">materials_project_configuration</span> <span class="o">=</span> <span class="n">SETTINGS</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;PMG_MAPI_KEY&quot;</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">materials_project_configuration</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="k">if</span> <span class="n">package_options</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">package_options</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">DEFAULT_PACKAGE_OPTIONS</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">package_options</span> <span class="o">=</span> <span class="n">package_options</span>

<div class="viewcode-block" id="ChemEnvConfig.setup"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.utils.chemenv_config.html#pymatgen.analysis.chemenv.utils.chemenv_config.ChemEnvConfig.setup">[docs]</a>    <span class="k">def</span> <span class="nf">setup</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">=&gt; Configuration of the ChemEnv package &lt;=&#39;</span><span class="p">)</span>
            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Current configuration :&#39;</span><span class="p">)</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">has_materials_project_access</span><span class="p">:</span>
                <span class="nb">print</span><span class="p">(</span><span class="s1">&#39; - Access to materials project is configured (add test ?)&#39;</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="nb">print</span><span class="p">(</span><span class="s1">&#39; - No access to materials project&#39;</span><span class="p">)</span>
            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39; - Package options :&#39;</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">key</span><span class="p">,</span> <span class="n">val</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">package_options</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;     </span><span class="si">{}</span><span class="s1">   :   </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">key</span><span class="p">),</span> <span class="nb">str</span><span class="p">(</span><span class="n">val</span><span class="p">)))</span>
            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">Choose in the following :&#39;</span><span class="p">)</span>
            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39; &lt;1&gt; + &lt;ENTER&gt; : configuration of the package options (strategy, ...)&#39;</span><span class="p">)</span>
            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39; &lt;q&gt; + &lt;ENTER&gt; : quit without saving configuration&#39;</span><span class="p">)</span>
            <span class="n">test</span> <span class="o">=</span> <span class="nb">input</span><span class="p">(</span><span class="s1">&#39; &lt;S&gt; + &lt;ENTER&gt; : save configuration and quit</span><span class="se">\n</span><span class="s1"> ... &#39;</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">test</span> <span class="o">==</span> <span class="s1">&#39;1&#39;</span><span class="p">:</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">setup_package_options</span><span class="p">()</span>
            <span class="k">elif</span> <span class="n">test</span> <span class="o">==</span> <span class="s1">&#39;q&#39;</span><span class="p">:</span>
                <span class="k">break</span>
            <span class="k">elif</span> <span class="n">test</span> <span class="o">==</span> <span class="s1">&#39;S&#39;</span><span class="p">:</span>
                <span class="n">config_file</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
                <span class="k">break</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="nb">print</span><span class="p">(</span><span class="s1">&#39; ... wrong key, try again ...&#39;</span><span class="p">)</span>
            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">test</span> <span class="o">==</span> <span class="s1">&#39;S&#39;</span><span class="p">:</span>
            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Configuration has been saved to file &quot;</span><span class="si">{}</span><span class="s1">&quot;&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">config_file</span><span class="p">))</span></div>

    <span class="nd">@property</span>
    <span class="k">def</span> <span class="nf">has_materials_project_access</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">materials_project_configuration</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span>

<div class="viewcode-block" id="ChemEnvConfig.setup_package_options"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.utils.chemenv_config.html#pymatgen.analysis.chemenv.utils.chemenv_config.ChemEnvConfig.setup_package_options">[docs]</a>    <span class="k">def</span> <span class="nf">setup_package_options</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">package_options</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">DEFAULT_PACKAGE_OPTIONS</span>
        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Choose between the following strategies : &#39;</span><span class="p">)</span>
        <span class="n">strategies</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">strategies_class_lookup</span><span class="o">.</span><span class="n">keys</span><span class="p">())</span>
        <span class="k">for</span> <span class="n">istrategy</span><span class="p">,</span> <span class="n">strategy</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">strategies</span><span class="p">):</span>
            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39; &lt;</span><span class="si">{}</span><span class="s1">&gt; : </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">istrategy</span> <span class="o">+</span> <span class="mi">1</span><span class="p">),</span> <span class="n">strategy</span><span class="p">))</span>
        <span class="n">test</span> <span class="o">=</span> <span class="nb">input</span><span class="p">(</span><span class="s1">&#39; ... &#39;</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">package_options</span><span class="p">[</span><span class="s1">&#39;default_strategy&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;strategy&#39;</span><span class="p">:</span> <span class="n">strategies</span><span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">test</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">],</span> <span class="s1">&#39;strategy_options&#39;</span><span class="p">:</span> <span class="p">{}}</span>
        <span class="n">strategy_class</span> <span class="o">=</span> <span class="n">strategies_class_lookup</span><span class="p">[</span><span class="n">strategies</span><span class="p">[</span><span class="nb">int</span><span class="p">(</span><span class="n">test</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">]]</span>
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">strategy_class</span><span class="o">.</span><span class="n">STRATEGY_OPTIONS</span><span class="p">)</span> <span class="o">&gt;</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">option</span><span class="p">,</span> <span class="n">option_dict</span> <span class="ow">in</span> <span class="n">strategy_class</span><span class="o">.</span><span class="n">STRATEGY_OPTIONS</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="k">while</span> <span class="kc">True</span><span class="p">:</span>
                    <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;  =&gt; Enter value for option &quot;</span><span class="si">{}</span><span class="s1">&quot; &#39;</span>
                          <span class="s1">&#39;(&lt;ENTER&gt; for default = </span><span class="si">{}</span><span class="s1">)</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">option</span><span class="p">,</span>
                                                                <span class="nb">str</span><span class="p">(</span><span class="n">option_dict</span><span class="p">[</span><span class="s1">&#39;default&#39;</span><span class="p">])))</span>
                    <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;     Valid options are :</span><span class="se">\n</span><span class="s1">&#39;</span><span class="p">)</span>
                    <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;       </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">option_dict</span><span class="p">[</span><span class="s1">&#39;type&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">allowed_values</span><span class="p">))</span>
                    <span class="n">test</span> <span class="o">=</span> <span class="nb">input</span><span class="p">(</span><span class="s1">&#39;     Your choice : &#39;</span><span class="p">)</span>
                    <span class="k">if</span> <span class="n">test</span> <span class="o">==</span> <span class="s1">&#39;&#39;</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">package_options</span><span class="p">[</span><span class="s1">&#39;default_strategy&#39;</span><span class="p">][</span><span class="s1">&#39;strategy_options&#39;</span><span class="p">][</span><span class="n">option</span><span class="p">]</span> <span class="o">=</span> <span class="n">option_dict</span><span class="p">[</span><span class="s1">&#39;type&#39;</span><span class="p">](</span>
                            <span class="n">strategy_class</span><span class="o">.</span><span class="n">STRATEGY_OPTIONS</span><span class="p">[</span><span class="n">option</span><span class="p">][</span><span class="s1">&#39;default&#39;</span><span class="p">])</span>
                        <span class="k">break</span>
                    <span class="k">try</span><span class="p">:</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">package_options</span><span class="p">[</span><span class="s1">&#39;default_strategy&#39;</span><span class="p">][</span><span class="s1">&#39;strategy_options&#39;</span><span class="p">][</span><span class="n">option</span><span class="p">]</span> <span class="o">=</span> <span class="n">option_dict</span><span class="p">[</span><span class="s1">&#39;type&#39;</span><span class="p">](</span><span class="n">test</span><span class="p">)</span>
                        <span class="k">break</span>
                    <span class="k">except</span> <span class="ne">ValueError</span><span class="p">:</span>
                        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Wrong input for option </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">option</span><span class="p">))</span></div>

<div class="viewcode-block" id="ChemEnvConfig.package_options_description"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.utils.chemenv_config.html#pymatgen.analysis.chemenv.utils.chemenv_config.ChemEnvConfig.package_options_description">[docs]</a>    <span class="k">def</span> <span class="nf">package_options_description</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">out</span> <span class="o">=</span> <span class="s1">&#39;Package options :</span><span class="se">\n</span><span class="s1">&#39;</span>
        <span class="n">out</span> <span class="o">+=</span> <span class="s1">&#39; - Maximum distance factor : </span><span class="si">{:.4f}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">package_options</span><span class="p">[</span><span class="s1">&#39;default_max_distance_factor&#39;</span><span class="p">])</span>
        <span class="n">out</span> <span class="o">+=</span> <span class="s1">&#39; - Default strategy is &quot;</span><span class="si">{}</span><span class="s1">&quot; :</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">package_options</span><span class="p">[</span><span class="s1">&#39;default_strategy&#39;</span><span class="p">][</span><span class="s1">&#39;strategy&#39;</span><span class="p">])</span>
        <span class="n">strategy_class</span> <span class="o">=</span> <span class="n">strategies_class_lookup</span><span class="p">[</span><span class="bp">self</span><span class="o">.</span><span class="n">package_options</span><span class="p">[</span><span class="s1">&#39;default_strategy&#39;</span><span class="p">][</span><span class="s1">&#39;strategy&#39;</span><span class="p">]]</span>
        <span class="n">out</span> <span class="o">+=</span> <span class="s1">&#39;</span><span class="si">{}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">strategy_class</span><span class="o">.</span><span class="n">STRATEGY_DESCRIPTION</span><span class="p">)</span>
        <span class="n">out</span> <span class="o">+=</span> <span class="s1">&#39;   with options :</span><span class="se">\n</span><span class="s1">&#39;</span>
        <span class="k">for</span> <span class="n">option</span><span class="p">,</span> <span class="n">option_dict</span> <span class="ow">in</span> <span class="n">strategy_class</span><span class="o">.</span><span class="n">STRATEGY_OPTIONS</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
            <span class="n">out</span> <span class="o">+=</span> <span class="s1">&#39;     - </span><span class="si">{}</span><span class="s1"> : </span><span class="si">{}</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">option</span><span class="p">,</span>
                                             <span class="bp">self</span><span class="o">.</span><span class="n">package_options</span><span class="p">[</span><span class="s1">&#39;default_strategy&#39;</span><span class="p">][</span><span class="s1">&#39;strategy_options&#39;</span><span class="p">][</span><span class="n">option</span><span class="p">])</span>
        <span class="k">return</span> <span class="n">out</span></div>

<div class="viewcode-block" id="ChemEnvConfig.save"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.utils.chemenv_config.html#pymatgen.analysis.chemenv.utils.chemenv_config.ChemEnvConfig.save">[docs]</a>    <span class="k">def</span> <span class="nf">save</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">root_dir</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">root_dir</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">home</span> <span class="o">=</span> <span class="n">expanduser</span><span class="p">(</span><span class="s2">&quot;~&quot;</span><span class="p">)</span>
            <span class="n">root_dir</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{}</span><span class="s1">/.chemenv&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">home</span><span class="p">)</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">exists</span><span class="p">(</span><span class="n">root_dir</span><span class="p">):</span>
            <span class="n">makedirs</span><span class="p">(</span><span class="n">root_dir</span><span class="p">)</span>
        <span class="n">config_dict</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;package_options&#39;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">package_options</span><span class="p">}</span>
        <span class="n">config_file</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{}</span><span class="s1">/config.json&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">root_dir</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">exists</span><span class="p">(</span><span class="n">config_file</span><span class="p">):</span>
            <span class="n">test</span> <span class="o">=</span> <span class="nb">input</span><span class="p">(</span><span class="s1">&#39;Overwrite existing configuration ? (&lt;Y&gt; + &lt;ENTER&gt; to confirm)&#39;</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">test</span> <span class="o">!=</span> <span class="s1">&#39;Y&#39;</span><span class="p">:</span>
                <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Configuration not saved&#39;</span><span class="p">)</span>
                <span class="k">return</span> <span class="n">config_file</span>
        <span class="n">f</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">config_file</span><span class="p">,</span> <span class="s1">&#39;w&#39;</span><span class="p">)</span>
        <span class="n">json</span><span class="o">.</span><span class="n">dump</span><span class="p">(</span><span class="n">config_dict</span><span class="p">,</span> <span class="n">f</span><span class="p">)</span>
        <span class="n">f</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
        <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Configuration saved&#39;</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">config_file</span></div>

<div class="viewcode-block" id="ChemEnvConfig.auto_load"><a class="viewcode-back" href="../../../../../pymatgen.analysis.chemenv.utils.chemenv_config.html#pymatgen.analysis.chemenv.utils.chemenv_config.ChemEnvConfig.auto_load">[docs]</a>    <span class="nd">@classmethod</span>
    <span class="k">def</span> <span class="nf">auto_load</span><span class="p">(</span><span class="bp">cls</span><span class="p">,</span> <span class="n">root_dir</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="k">if</span> <span class="n">root_dir</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">home</span> <span class="o">=</span> <span class="n">expanduser</span><span class="p">(</span><span class="s2">&quot;~&quot;</span><span class="p">)</span>
            <span class="n">root_dir</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{}</span><span class="s1">/.chemenv&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">home</span><span class="p">)</span>
        <span class="n">config_file</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{}</span><span class="s1">/config.json&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">root_dir</span><span class="p">)</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">f</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">config_file</span><span class="p">,</span> <span class="s1">&#39;r&#39;</span><span class="p">)</span>
            <span class="n">config_dict</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">f</span><span class="p">)</span>
            <span class="n">f</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
            <span class="k">return</span> <span class="n">ChemEnvConfig</span><span class="p">(</span><span class="n">package_options</span><span class="o">=</span><span class="n">config_dict</span><span class="p">[</span><span class="s1">&#39;package_options&#39;</span><span class="p">])</span>

        <span class="k">except</span> <span class="ne">IOError</span><span class="p">:</span>
            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39;Unable to load configuration from file &quot;</span><span class="si">{}</span><span class="s1">&quot; ...&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">config_file</span><span class="p">))</span>
            <span class="nb">print</span><span class="p">(</span><span class="s1">&#39; ... loading default configuration&#39;</span><span class="p">)</span>
            <span class="k">return</span> <span class="n">ChemEnvConfig</span><span class="p">()</span></div></div>
</pre></div>

            <div class="clearer"></div>
          </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../../../pymatgen.html" >pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.analysis.chemenv.utils.chemenv_config</a></li> 
      </ul>
    </div>

    <div class="footer" role="contentinfo">
        &#169; Copyright 2011, Pymatgen Development Team.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
    </div>
<div class="footer">This page uses <a href="http://analytics.google.com/">
Google Analytics</a> to collect statistics. You can disable it by blocking
the JavaScript coming from www.google-analytics.com.
<script type="text/javascript">
  (function() {
    var ga = document.createElement('script');
    ga.src = ('https:' == document.location.protocol ?
              'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    ga.setAttribute('async', 'true');
    document.documentElement.firstChild.appendChild(ga);
  })();
</script>
</div>

  </body>
</html>